package com.zenith.article.controller;

import com.zenith.article.po.domain.ArtCategory;
import com.zenith.article.po.dto.ArtCategoryDTO;
import com.zenith.article.service.ArtCategoryService;
import com.zenith.common.annotation.request.SecurePostMapping;
import com.zenith.common.result.Result;
import com.zenith.common.result.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文章分类控制器
 *
 * @author zenith
 * @since 2025-08-29
 */
@RestController
@RequestMapping("/api/article/category")
@Tag(name = "文章分类管理", description = "文章分类相关接口")
public class ArtCategoryController {

    @Autowired
    private ArtCategoryService artCategoryService;

    /**
     * 分页查询文章分类
     */
    @Operation(summary = "分页查询文章分类")
    @SecurePostMapping("/getArtCategoryPage/page")
    public Result<PageResult<ArtCategory>> getArtCategoryPage(ArtCategoryDTO query) {
        PageResult<ArtCategory> pageResult = artCategoryService.getArtCategoryPage(query);
        return Result.success(pageResult);
    }

    /**
     * 获取分类树结构
     */
    @Operation(summary = "获取分类树结构")
    @SecurePostMapping("/getArtCategoryTree/tree")
    public Result<List<ArtCategory>> getArtCategoryTree() {
        List<ArtCategory> tree = artCategoryService.getArtCategoryTree();
        return Result.success(tree);
    }

    /**
     * 创建文章分类
     */
    @Operation(summary = "创建文章分类")
    @SecurePostMapping("/createArtCategory")
    public Result<Boolean> createArtCategory(@RequestBody ArtCategoryDTO categoryDTO) {
        boolean result = artCategoryService.createArtCategory(categoryDTO);
        return Result.success(result);
    }

    /**
     * 更新文章分类
     */
    @Operation(summary = "更新文章分类")
    @SecurePostMapping("/updateArtCategory")
    public Result<Boolean> updateArtCategory(@RequestBody ArtCategoryDTO categoryDTO) {
        boolean result = artCategoryService.updateArtCategory(categoryDTO);
        return Result.success(result);
    }

    /**
     * 删除文章分类
     */
    @Operation(summary = "删除文章分类")
    @SecurePostMapping("/deleteArtCategory/{id}")
    public Result<Boolean> deleteArtCategory(@PathVariable Long id) {
        boolean result = artCategoryService.deleteArtCategory(id);
        return Result.success(result);
    }
}